package codeRandomThoughts.Test1605给定行和列的和求可行矩阵;

public class Solution {
    public int[][] restoreMatrix(int[] rowSum, int[] colSum) {
        //结果矩阵的长和宽
        int m = rowSum.length;
        int n = colSum.length;

        //结果矩阵
        int[][] res = new int[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                res[i][j] = Math.min(rowSum[i], colSum[j]);
                //用过的数字要从总和中删除
                rowSum[i] -= res[i][j];
                colSum[j] -= res[i][j];
            }
        }

        return res;
    }
}
